﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>企业缴费</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />    
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
    html, body
    {
        font-size:12px;
        padding:0;
        margin:0;
        border:0;
        height:100%;
        overflow:hidden;
    }
    </style>
</head>
<body>       
    <form id="form1" method="post">
    <div id="companyForm" class="form" >
    <fieldset style="border: solid 1px #aaa; padding: 3px;">
        <legend>企业基本信息</legend>
        <div style="padding: 5px;">
            <table style="border:1px solid #fff">
                <tr>
                    <td style="width: 70px;">
                        企业名称：
                    </td>
                    <td style="width: 150px;">
                        <input name="cu_name" class="mini-textbox" required="true" allowInput="false" />
                    </td>
                    <td style="width: 70px;">
                        公司地址：
                    </td>
                    <td style="width: 150px;">
                        <input name="cu_address" class="mini-textbox" required="true" allowInput="false" />
                    </td>
                     <td style="width: 70px;">
                        营业执照：
                    </td>
                    <td style="width: 150px;">
                        <input name="cu_license" class="mini-textbox" required="true" allowInput="false" />
                    </td>
                </tr>
                  <tr>
                    <td style="width: 70px;">
                        联系人：
                    </td>
                    <td style="width: 150px;">
                        <input name="cu_contact" class="mini-textbox" required="true"  allowInput="false" />
                    </td>
                    <td style="width: 70px;">
                        联系电话：
                    </td>
                    <td>
                        <input name="cu_tel" class="mini-textbox" required="true"  allowInput="false" />
                    </td>
                     <td style="width: 70px;">
                        Email：
                    </td>
                    <td style="width: 150px;">
                        <input name="cu_email" class="mini-textbox" required="true"  allowInput="false" />
                    </td>
                </tr>
                <tr>
                    <td>
                        备注：
                    </td>
                    <td colspan="5">
                        <input name="cu_introduce" class="mini-textarea" required="true"  allowInput="false" style="width:100%" />
                    </td>
                </tr>
            </table>
        </div>
    </fieldset>
</div>
<!--------------------------------------------------->
        <input name="cu_no" class="mini-hidden" />
        <div style="padding-left:11px;padding-bottom:5px;">
            <table style="table-layout:fixed;">
               <tr>
                   <td>服务项目：</td>
                   <td>
                       <input id="btnEdit1" name="fee_id" class="mini-buttonedit" onbuttonclick="onButtonEdit" />
                   </td>
                   <td>费用：</td>
                   <td>
                       <input name="expense" class="mini-textbox" emptyText="请输入费用金额" />
                   </td>
                   <td>
                       <a class="mini-button" onclick="onAdd" style="width: 80px; margin-right: 20px;">新增服务</a>
                   </td>
               </tr>                
            </table>
        </div>
        </form>
        <fieldset style="border:solid 1px #aaa;padding:3px;">
            <legend >本次新增服务</legend>
            <div style="padding:5px;">
       <div id="datagrid1" class="mini-datagrid" style="width:100%;height:250px;"  allowResize="true"
         idField="id" ondrawsummarycell="onDrawSummaryCell"  allowCellEdit="true" allowCellSelect="true"  showFooter="false">
        <div property="columns">
            <div name="action" width="20" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">#</div>
            <div visible="true" field="cu_no" width="100" allowSort="true" headerAlign="center" >企业编号</div>
            <div field="cu_name" width="120" headerAlign="center" allowSort="true">企业名称</div>                          
            <div field="cu_tel" width="100" allowSort="true" headerAlign="center">联系电话</div>
            <div  visible="true" field="fee_id" width="100" allowSort="true" headerAlign="center">标示</div>         
            <div field="serviceName" width="100" allowSort="true" headerAlign="center" url="" >服务名称</div>
            <div field="expense" currencyUnit="￥" width="100" allowSort="true" headerAlign="center">费用</div>
        </div>
    </div>                       
            </div>
        </fieldset>
        <div style="text-align:center;padding:10px;">               
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>
    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("form1");
        var dataGrid = mini.get("datagrid1");

        function addService() {
            var data = form.getData();
            data["serviceName"] = mini.get("btnEdit1").getText();
            
            if (data.expense == "" || data.fee_id == null) {
                mini.alert("请先选择服务，并输入费用金额！");
                return;
            } else {
                dataGrid.addRow(data, 0);
            }
        }

        function onAdd(e) {
            addService();
        }

        function onDrawSummaryCell(e) {
            var result = e.result;
            var grid = e.sender;
            var rows = e.data;

            if (e.field == "expense") {
                var total = 0;
                for (var i = 0, l = rows.length; i < l; i++) {
                    var row = rows[i];
                    var t = row.expense;
                    if (isNaN(t)) continue;
                    total += t;
                }

                e.cellHtml = "总计: " + total;
            }
        }


        function SaveData() {
            var o = dataGrid.getData();

            dataGrid.validate();
            if (dataGrid.isValid() == false) return;

            var json = mini.encode(o);
            $.ajax({
                url: bootPATH + "../data/payservice.aspx?method=SavePay",
                type: 'post',
                data: { data: json },
                cache: false,
                success: function (text) {
                        mini.confirm(text+"是否继续添加服务？", "确定？",
                            function (action) {
                                if (action == "ok") {
                                    dataGrid.clearRows();
                                } else {
                                    CloseWindow("save");
                                }
                            }
                        );
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }

        ////////////////////
        //-----标准方法接口定义
        function SetData(data) {
            if (data.action == "add") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data.row);

//                $.ajax({
//                    url: "../data/payservice.aspx?method=addNewPay&id=" + data.cu_no,
//                    cache: false,
//                    success: function (text) {
//                        var o = mini.decode(text);
//                        form.setData(o);
//                        form.setChanged(false);

//                        onDeptChanged();
//                        mini.getbyName("position").setValue(o.position);
//                    }
                //                });
                //alert(data);
                form.setData(data);
            }
        }
        ////////////////////
        //标准方法接口定义-----
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        //////////////////////////////////
//        function onDeptChanged(e) {
//            var deptCombo = mini.getbyName("dept_id");
//            var positionCombo = mini.getbyName("position");
//            var dept_id = deptCombo.getValue();

//            positionCombo.load("../data/AjaxService.aspx?method=GetPositionsByDepartmenId&id=" + dept_id);
//            positionCombo.setValue("");
//        }
// function adds() {
//        var data = form.getData();
//            var items = new Array();
//            items.push(data);
////            grid1.removeRows(items);
//            dataGrid.addRows(items);
//        }
        


        function onButtonEdit(e) {
            var btnEdit = this;
            mini.open({
                url: bootPATH + "../payservice/selectTreeServices.html",
                showMaxButton: true,
                title: "弹出多选",
                width: 650,
                height: 380,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.SetData(null);
                },
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();

                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);

                        btnEdit.setValue(data.Id);
                        btnEdit.setText(data.Name);
                    }
                }
            });
        }
    </script>
</body>
</html>
